package com.jie.boot.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import spring.data.jpa.repository.CommonJpaRepository;
import spring.data.jpa.repository.support.SearchFilter.Operator;
import spring.data.jpa.tools.DBHelper;

import com.jie.boot.domain.Student;
import com.jie.boot.domain.StudentPk;

@Service
public class StudentService {

    @Resource(name = "studentRepository")
    private CommonJpaRepository<Student, StudentPk> studentRepository;

    @Transactional
    public void save(Student entity) {
        studentRepository.save(entity);
    }

    public List<Student> findBy(String field, Object value) {
        return studentRepository.findAll(DBHelper.newSpecification(Student.class).build(field, value, Operator.EQ)
                .specification());
    }
}
